﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AliboboStockLib.linq;
using AliboboStockLib.util;

namespace AliboboStockLib.stockupdater.sbdetail
{
    public class OtcSBDetailUpdater:SBDetailUpdater
    {

        public override String getMarketName()
        {
            return "otc";
        }

        public static List<String> getAllOtcCodes()
        {
            MyStockDataContext context = getContext();
            String sql = "select 代號 from StockIndex where StockIndex.市場='otc' and StockIndex.catid is not null order by StockIndex.代號";
            List<String> result = context.ExecuteQuery<String>(sql).ToList<String>();
            return result;
        }

        protected override void prepareSBTask(DateTime d)
        {
            //他比較簡單..就是
            MyStockDataContext context = getContext();
            List<String> allCodes = getAllOtcCodes();
            List<String> exists = (from sc in context.SBDataTasks where sc.日期.Equals(d) select sc.StockCode).ToList<String>();
            
            HashSet<String> toCreate = filterToCreate(exists, allCodes);

            if (toCreate.Count == 0)
                return;
            createSBTask(toCreate, d);

        }
    }
}
